<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>V0.13测试中</title>
</head>
<style>
    table {
        border-collapse: collapse;
    }

    td {
        border: 1px solid gray;
    }

    .hidden {
        display: none;
    }

    .input-L30 {
        width: 50px;
    }

    .input-L60 {
        width: 60px;
    }
</style>

<body>
    <script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/xlsx.full.min.js"></script>
    <div id="showExcll"></div>
    <script>
        var excll; // 工作簿    
        var sheet; // sheet页  
        var sheet_num = 0;//当前sheet页
        var sheet_max = 0;//sheet页总数
        var Excel1 = document.getElementById('showExcll');
        // 读取文件
        function readFile(obj) {
            if (!obj.files) return;
            var file = obj.files[0];
            var reader = new FileReader();
            reader.onload = function (e) {
                var data = e.target.result;
                // 解析文件，读取成 html    
                excll = XLSX.read(data, { type: 'binary' });
                sheet = excll.Sheets[excll.SheetNames[sheet_num]];
                sheet_max = excll.SheetNames.length - 1;
                //console.log(`sheet_max现在是 ${sheet_max}`)
                Excel1.innerHTML = XLSX.utils.sheet_to_html(sheet);
                //把按钮放出来
                document.getElementById('changeSheetButton').style.display = 'block'
                document.getElementById('sheet_numNO').innerText = `你在第${sheet_num}页！`;
            };
            // reader.readAsBinaryString(file);
            reader.readAsArrayBuffer(file);
        }
        function changeSheet(str) {
            if (!excll) return;
            if (str == 0)
                sheet_num > 0 ? sheet_num-- : sheet_num = sheet_max;
            else if (str == 2)
                sheet_num < sheet_max ? sheet_num++ : sheet_num = 0;
            sheet = excll.Sheets[excll.SheetNames[sheet_num]];
            Excel1.innerHTML = XLSX.utils.sheet_to_html(sheet);
            document.getElementById('sheet_numNO').innerText = `你在第${sheet_num}页！`;
        }
        var data1 = [
            [0.8, 0, 1.6],
            [1.4, 1.5, 0],
            [0, 1.8, 0]
        ]
        var data2 = [
            [0.8, 1.4, 0],
            [0, 1.5, 1.8],
            [1.6, 0, 0]]
        function updateCell(side) {
            var selectPL = document.getElementById('attackPL');
            var selectNPC = document.getElementById('attackNPC');
            var ACKpowerPL = parseFloat(document.getElementById('ACKpowerPL').value) || 0;
            var ACKpowerNPC = parseFloat(document.getElementById('ACKpowerNPC').value) || 0;
            var DEFpowerPL = parseFloat(document.getElementById('DEFpowerPL').value) || 0;
            var DEFpowerNPC = parseFloat(document.getElementById('DEFpowerNPC').value) || 0;
            var EXACKpointPL = parseFloat(document.getElementById('exACKpointPL').value) || 0;//PL额外攻击倍率增减
            var EXACKpointNPC = parseFloat(document.getElementById('exACKpointNPC').value) || 0;//NPC额外攻击倍率增减
            var damageUpPL = parseFloat(document.getElementById('damageUpPL').value) || 0;//己方加伤
            var damageDownPL = parseFloat(document.getElementById('damageDownPL').value) || 0;//己方脆弱
            var damageUpNPC = parseFloat(document.getElementById('damageUpNPC').value) || 0;//敌方加伤
            var damageDownNPC = parseFloat(document.getElementById('damageDownNPC').value) || 0;//敌方脆弱
            var SkillPowerPL= parseFloat(document.getElementById('SkillPowerPL').value) || 0;//己方技能倍率
            var SkillPowerNPC= parseFloat(document.getElementById('SkillPowerNPC').value) || 0;//敌方技能倍率
            damageUpPL = 1 + damageUpPL / 100; damageUpNPC = 1 + damageUpNPC / 100;
            damageDownPL = 1 - damageDownPL / 100; damageDownNPC = 1 - damageDownNPC / 100;
            SkillPowerNPC/=100;SkillPowerPL/=100;
            var AindexPL = selectPL.selectedIndex;
            var AindexNPC = selectNPC.selectedIndex;
            var cellDiv = document.getElementById('out1');
            if (!cellDiv) return;
            var value1 = data1[AindexNPC][AindexPL];//基础造伤
            var value2 = data2[AindexNPC][AindexPL];//基础受伤
            var finPointToNPC, finPointToPL;//总造伤基础,总受伤基础
            if (AindexNPC == 2 && AindexPL == 1) {//NPC防御,玩家重击的情况
                finPointToNPC = (value1 + EXACKpointPL - (EXACKpointNPC < 0 ? EXACKpointNPC : 0));
                finPointToPL = value2;
            }
            else if (AindexNPC == 1 && AindexPL == 2) {//玩家防御，NPC重击的情况
                finPointToNPC = value1;
                finPointToPL = (value2 + EXACKpointNPC - (EXACKpointPL < 0 ? EXACKpointPL : 0));
            }
            else if (AindexNPC == 2 && AindexPL == 2) {
                finPointToNPC = 0;
                finPointToPL = 0;
            }
            else {
                if (value1 == 0) EXACKpointPL = 0;
                if (value2 == 0) EXACKpointNPC = 0;
                finPointToNPC = (value1 + EXACKpointPL);
                finPointToPL = (value2 + EXACKpointNPC);
            }
            var damageNPC = Math.max((finPointToPL * (ACKpowerNPC*SkillPowerNPC - DEFpowerPL)) * damageUpNPC * damageDownPL, 0).toFixed(1);//这是PL受到的伤害
            var damagePL = Math.max((finPointToNPC * (ACKpowerPL*SkillPowerPL - DEFpowerNPC)) * damageUpPL * damageDownNPC, 0).toFixed(1);//这个是PL造成的伤害
            var finPointPL = Math.max(0, finPointToPL).toFixed(2);
            var finPointNPC = Math.max(0, finPointToNPC).toFixed(2);
            cellDiv.innerText = `造伤基础是${finPointNPC}倍，受伤基础是${finPointPL}倍\n我方受到的伤害为${damageNPC}，对敌方造成的伤害为${damagePL}。`;
        }
        window.onload = function () {
            updateCell();
        }
    </script>
    <div>
        <input type="file" onchange="readFile(this)" />
    </div><br>
    <label id="sheet_numNO"></label>
    <div id="changeSheetButton" class="hidden">
        <button onclick="changeSheet(0)">上一页！</button>
        <button onclick="changeSheet(2)">下一页！</button>
    </div><br>
    <label for="attackPL">选择己方行动:</label>
    <select id="attackPL" name="attackPL" onchange="updateCell()">
        <option value="apple">轻击</option>
        <option value="banana">重击</option>
        <option value="cherry">防御</option>
    </select> + <input type="number" id="exACKpointPL" class="input-L30" step="0.1" onchange="updateCell()">基础倍率 *
    <input type="number" id="SkillPowerPL" class="input-L30" value="100" min="0" step="10" onchange="updateCell()">%技能倍率<br>
    <label for="attackNPC">选择敌方行动:</label>
    <select id="attackNPC" name="attackNPC" onchange="updateCell()">
        <option value="apple">轻击</option>
        <option value="banana">重击</option>
        <option value="cherry">防御</option>
    </select> + <input type="number" id="exACKpointNPC" class="input-L30" step="0.1" onchange="updateCell()">基础倍率 *
    <input type="number" id="SkillPowerNPC" class="input-L30" value="100" min="0" step="10" onchange="updateCell()">%技能倍率<br><br>
    <div>
        <div>我方攻击力：<input type="number" class="input-L60" id="ACKpowerPL" value="50" onchange="updateCell()" /></div>
        敌方攻击力：<input type="number" class="input-L60" id="ACKpowerNPC" value="20" onchange="updateCell()" /><br>

        <div id="DEFpower" class="hidden">
            我方防御力：<input type="number" class="input-L60" id="DEFpowerPL" value="0" onchange="updateCell()" />
            敌方防御力：<input type="number" class="input-L60" id="DEFpowerNPC" value="0" onchange="updateCell()" />
        </div>
    </div>
    <div>
        我方伤害加成：<input type="number" id="damageUpPL" class="input-L30" onchange="updateCell()">%&emsp;我方伤害减免：<input
            type="number" id="damageDownPL" class="input-L30" onchange="updateCell()">%<br>
        敌方伤害加成：<input type="number" id="damageUpNPC" class="input-L30" onchange="updateCell()">%&emsp;敌方伤害减免：<input
            type="number" id="damageDownNPC" class="input-L30" onchange="updateCell()">%
    </div><br>
    <label>结果可能会显示在这里：<div id="out1"></div>
        </div></label>
</body>

</html>